package com.community.zhihuishequ.view.base;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.widget.Toast;

import com.community.zhihuishequ.net.AppRestService;

import butterknife.ButterKnife;
import butterknife.Unbinder;

/**
 * Created by Rick on 17/11/22.
 */

public abstract class BaseActivity extends AppCompatActivity {
    private Toast toast;
    protected Unbinder unbinder;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    protected void initActionBar(Toolbar toolbar, boolean useHomeAsBack) {
        if (toolbar != null) {
            super.setSupportActionBar(toolbar);
        }
        ActionBar actionBar = getSupportActionBar();
        if (actionBar != null) {
            actionBar.setDisplayHomeAsUpEnabled(useHomeAsBack);
        }
    }

    protected void showToast(int resId) {
        showToast(getString(resId));
    }

    protected void showToast(String msg) {
        if (toast != null) {
            toast.cancel();
        }
        toast = Toast.makeText(this, msg, Toast.LENGTH_LONG);
        toast.show();
    }

    protected final String getBaseUrl() {
        return AppRestService.BASE_URL;
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        if (unbinder != null) {
            unbinder.unbind();
        }
    }
}
